#include "qimagewidget.h"

#include "qimageview.h"


#include "../../libs/coreLib/styledbar.h"
#include "../../libs/coreLib/qactiontoolbar.h"
#include "../../libs/coreLib/qsoftcore.h"
#include "../../libs/sharedLib/qresourcemanager.h"

#include <QVBoxLayout>

QImageWidget::QImageWidget(QWidget *parent) :
    QWidget(parent),
    m_styledBar(new CORELIB::StyledBar),
    m_imageWidget(new QImageView)
{
    QVBoxLayout *v=new QVBoxLayout;
    v->setMargin(0);
    v->setSpacing(0);
    v->addWidget(m_styledBar);
    v->addWidget(m_imageWidget);
    this->setLayout(v);

    CORELIB::QActionToolBar *toolbar=new CORELIB::QActionToolBar;
    QHBoxLayout *h=new QHBoxLayout;
    h->setContentsMargins(5,0,5,0);
    h->setSpacing(5);


    CORELIB::QSoftCore *core=CORELIB::QSoftCore::getCore();

    QLabel *label=new QLabel(tr("Image View"));
    label->setStyleSheet("color:rgb(255,255,255);");
    h->addWidget(label,0);
    h->addWidget(toolbar,1);

    m_styledBar->setLayout(h);
    QList<QAction*> list;
    QAction* ac;

    ac=new QAction(this);
    ac->setSeparator(true);
    list.append(ac);

    ac=core->action("ImageView-Fit");
    if(ac!=NULL)
    {
        list.append(ac);
    }

    ac=core->action("ImageView-Original");
    if(ac!=NULL)
    {
        list.append(ac);
    }

    ac=core->action("ImageView-Zoomin");
    if(ac!=NULL)
    {
        list.append(ac);
    }

    ac=core->action("ImageView-Zoomout");
    if(ac!=NULL)
    {
        list.append(ac);
    }

    ac=new QAction(this);
    ac->setSeparator(true);
    list.append(ac);

    toolbar->addButtonActions(list);
}

void QImageWidget::setImage(const QString &firstName, const QString &lastName)
{
    QByteArray data=CORELIB::QSoftCore::getCore()->resourceManager()->resourceData(firstName,lastName);
    m_imageWidget->setImage(data);
}
